vpci: refuse BAR writes only if the BAR is mapped
authorRoger Pau Monné <roger.pau@citrix.com>
Fri, 28 Oct 2022 09:40:45 +0000 (11:40 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 28 Oct 2022 09:40:45 +0000 (11:40 +0200)
commit7abd7bc1626d25ada03c1cff2e8c2ce1a5cc3cbf
tree71db1b9d6bf82d3430d95614489caf7dc0b71b23
parent53d9133638c3f940a53df60352fabb0963d67ad3
vpci: refuse BAR writes only if the BAR is mapped

Writes to the BARs are ignored if memory decoding is enabled for the
device, and the same happen with ROM BARs if the write is an attempt
to change the position of the BAR without disabling it first.

The reason of ignoring such writes is a limitation in Xen, as it would
need to unmap the BAR, change the address, and remap the BAR at the
new position, which the current logic doesn't support.

Some devices however seem to (wrongly) have the memory decoding bit
hardcoded to enabled, and attempts to disable it don't get reflected
on the command register.

This causes issues for well behaved domains that disable memory
decoding and then try to size the BARs, as vPCI will think memory
decoding is still enabled and ignore the write.

Since vPCI doesn't explicitly care about whether the memory decoding
bit is disabled as long as the BAR is not mapped in the domain p2m use
the information in the vpci_bar to check whether the BAR is mapped,
and refuse writes only based on that information.  This workarounds
the issue, and allows domains to size and reposition the BARs properly.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
xen/drivers/vpci/header.c
xen/include/xen/vpci.h